<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends CController
{
	/**
	 * @var string the default layout for the controller view. Defaults to '//layouts/column1',
	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
	 */
	public $layout = '//layouts/main';
	/**
	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.
	 */
	public $menu = array();
	/**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs = array();

//	public $jsIncludes = array();
//	public $cssIncludes = array();
	
	/**
	 * 
	 * Передается в jqueryData
	 * @var array
	 * getProfiles
	 */
	protected $scriptConfig = array();
	
	public function init()
	{
		parent::init();
		
		if ( isset($_REQUEST['api_id']) && isset($_REQUEST['viewer_id']) &&	isset($_REQUEST['auth_key']) )
  		{
  			$session=new CHttpSession;
  			$session->open();
  			$session['vk_params'] = array(
				/* Для авторизации */
				'api_id' => $_REQUEST['api_id'],
				'viewer_id' => $_REQUEST['viewer_id'],
				'auth_key' => $_REQUEST['auth_key'],
			);
  			$session->close();
  		}
 	}	
	
	protected function setScriptConfig($key, $value)
	{
		$this->scriptConfig[$key] = $value;
	}
	
	protected function renderJqueryData()
	{
		$data = "";
		foreach ($this->scriptConfig as $key => $value)
			$data .= " data-$key='$value'";
		
		return $data;			
	}
//	protected function afterRender($view, &$output)
//	{
//		$this->renderIncludes($output);
//	}
//	
//	protected function renderIncludes(&$output)
//	{
//		$head_tag = '</head>';
//		$extra_head = '';
//		
//		foreach ($this->jsIncludes as $url => $params)
//			$extra_head .= CHtml::scriptFile(Yii::app()->request->baseUrl.'/js/'.$url.'.js')."\n";
//			
//		foreach ($this->cssIncludes as $url => $params)
//			$extra_head .= CHtml::cssFile(Yii::app()->request->baseUrl.'/css/'.$url.'.css', $params['media'])."\n";
//
//		$output = preg_replace('#'.$head_tag.'#', $extra_head . $head_tag, $output);
//	}	
//	
//	protected function include_once_js($url)
//	{
//		$this->jsIncludes[$url] = $url;
//	}
//	
//	protected function include_once_css($url, $params = array())
//	{
//		$this->cssIncludes[$url] = $params;
//	}	
}
